package org.lanqiao.tjut.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.tjut.bean.UsersBean;
import org.lanqiao.tjut.myUtils.MyUtils;
import org.lanqiao.tjut.service.ServiceFactory;

public class UserInfoQuery extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		
		
        //设置编码  防止中文乱码
		request.setCharacterEncoding("UTF-8");
		
		String strOperationType = request.getParameter("opt");
		int iOpt = MyUtils.obj2Int(strOperationType);
	
		
		if (iOpt == 2) {
		
		UsersBean usersB =new UsersBean();

		usersB.setUsername(request.getParameter("txtUserName"));
		usersB.setUserage(MyUtils.obj2Int(request.getParameter("txtUserAge")));
		usersB.setUserage2(MyUtils.obj2Int(request.getParameter("txtUserAge2")));
		usersB.setUseraddress(request.getParameter("txtUserAddress"));
		usersB.setUsersex(request.getParameter("selectSext"));
		usersB.setUsertel(request.getParameter("txtUserTel"));

		// 查询操作
		List<UsersBean> lstUsersC = ServiceFactory.getUserInfoManagerServiceInstance().doQueryByParas(usersB);

		// 将需要显示的结果集放入session缓存中
		request.getSession().setAttribute("lstUsers", lstUsersC);
		//查询结果页

		request.getRequestDispatcher("logined/UserInfoManager/userInfoQuery.jsp").forward(request, response);
		}
		//获取需要显示的所有的数据集合
		List<UsersBean> lstUsers = ServiceFactory.getUserInfoManagerServiceInstance().getAllUsersInfo();
		//将需要显示的结果集放入session缓存中
		request.getSession().setAttribute("lstUsers", lstUsers);
		
		//清空request缓存中的对象
		request.removeAttribute("usersB");
		//转发到结果显示页面
		request.getRequestDispatcher("logined/UserInfoManager/userInfoQuery.jsp").forward(request, response);
		//response.sendRedirect("logined/UserInfoManager/userInfoAddDetail.jsp");
		
	}
	
}
